// 需要将initState变成一个immutable的对象
import { Map } from "immutable";

const initState = Map({
  count: 10,
  name: "tom",
  list: [1, 2, 3],
});

// 如果使用了immutable，在reducer函数里面就需要用set或者update来修改数据了
const reducer = (state = initState, action) => {
  switch (action.type) {
    case "add":
      return state.update("count", (v) => v + 1);
    case "minus":
      return state.update("count", (v) => v - 1);
    case "changeName":
      return state.set("name", action.name);
    default:
      return state;
  }
};

export default reducer;
